/**
 * Created:	2001-7-
 * By:		eeorange
 * About: 	hdu 1172 - Guess Number
 * Status:	accept 78ms
 */

#include <cstdio>
#include <cstring>
#include <ctime>
#include <iostream>
using namespace std;

struct Node{
	int num, a, b;
};

Node dt[110];
int n;

bool check(int num){
	char A[5], B[5];
	sprintf(A, "%d", num);
	for(int i=0; i<n; i++)
	{
		sprintf(B, "%d", dt[i].num);
		int cnt = 0;
		for(int j=0; j<4; j++) if(A[j] == B[j]) cnt++;
		if(cnt != dt[i].b) return false;
		char* p;
		cnt = 0;
		for(int j=0; j<4; j++) if((p = strchr(B, A[j])) != NULL){
			*p = 'v';	// 设置位，表示以访问过
			cnt++;
		}
		if(cnt != dt[i].a) return false;
	}
	return true;
}

			
int main(){
	#ifdef LOCAL
		freopen("data.in", "r", stdin);
	#endif
	while(scanf("%d", &n) && n)
	{
		for(int i=0; i<n; i++) 
			cin >> dt[i].num >> dt[i].a >> dt[i].b;
			
		int ok = 1, ans = -1;
		for(int i=1000; i<= 9999; i++)	if(check(i)){ 
			if(ans == -1) ans = i;
			else{
				ok = 0;
				break;
			}
		}
		if(ans != -1 && ok) printf("%d\n", ans);
		else printf("Not sure\n");
	}
	
	
	#ifdef LOCAL
		printf("\nTime used = %.3lf\n", (double)clock()/CLOCKS_PER_SEC);
		printf("****** END ******\n");
	#endif
	return 0;
}


